<%@ page contentType="text/html; charset=UTF-8" language="java"%>
<%@ page import="org.quickbundle.orgauth.rmpartytype.util.IRmPartyTypeConstants" %>
<%@page import="com.dfhc.util.CryptoHelper"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<%@ taglib uri="/dfhc" prefix="dfhc" %>
<!-- 全局js 和css包 -->
<%@ include file="/jsp/include/web/new/global.jsp" %>
<title>团体类型</title>
</head>
<body>
<dfhc:template templateUrl="/pubController/getLayoutTemp/?jspUrl=/temp/huiBodyTemp" >	 
 	<dfhc:region name="searchRegion"> 
	<form name="searchForm" id="searchForm" action="">
	<dfhc:div templateId="h_ui_div_search">
		<%=IRmPartyTypeConstants.TABLE_COLUMN_CHINESE.get("bs_keyword")%>:<dfhc:input templateId="h_ui_search_input" placeholder="" id="bs_keyword" name="bs_keyword"/>
		<dfhc:button templateId="h_ui_search_button" id="" name="" onclick="javascript:_searchData();" />
	</dfhc:div>
	</form>
     </dfhc:region> 
     <dfhc:region name="buttonRegion">
        <dfhc:div templateId="h_ui_div_table_button">
        <dfhc:span templateId="h_ui_button_span">
         <dfhc:button templateId="h_ui_add_button" onclick="_showPage('添加模块','/RmPartyTypeByHUI/addPage','100%','100%')" />
         <dfhc:button templateId="h_ui_update_button" onclick="singleEdit('修改模块','/RmPartyTypeByHUI/showPage','100%','100%')" />
		 <dfhc:button templateId="h_ui_delete_button" onclick="singleDelete('/RmPartyTypeByHUI/delete')" />
		<dfhc:button templateId="h_ui_detail_button" onclick="detail('团体类型详情','/RmPartyTypeByHUI/detail','100%','100%')" />
		</dfhc:span>
		<dfhc:span templateId="h_ui_total_record_num_span">${RM_PAGE_VO.recordCount}</dfhc:span>		
	    </dfhc:div>		       
     </dfhc:region> 
    <dfhc:region name="tableRegion">
    	<dfhc:table templateId="table_h_ui" >    	
		<dfhc:thead>
			<dfhc:tr> 
				<dfhc:th  width="25" >
				   <dfhc:checkbox name="allId" /> &nbsp;&nbsp;序号
				</dfhc:th>
				
				<dfhc:th width="100">
				   <dfhc:title templateId="title_h_ui" ><%=IRmPartyTypeConstants.TABLE_COLUMN_CHINESE.get("bs_keyword")%></dfhc:title>
				</dfhc:th>
				
				<dfhc:th width="100">
				   <dfhc:title templateId="title_h_ui" ><%=IRmPartyTypeConstants.TABLE_COLUMN_CHINESE.get("name")%> </dfhc:title>
				</dfhc:th>
				
				<%-- <dfhc:th width="100">
				   <dfhc:title templateId="title_h_ui" ><%=IRmPartyTypeConstants.TABLE_COLUMN_CHINESE.get("icon")%> </dfhc:title>
				</dfhc:th> --%>
				
				<dfhc:th width="100">
				   <dfhc:title templateId="title_h_ui" ><%=IRmPartyTypeConstants.TABLE_COLUMN_CHINESE.get("description")%> </dfhc:title>
				</dfhc:th>
				
				<dfhc:th width="100">
				   <dfhc:title templateId="title_h_ui" ><%=IRmPartyTypeConstants.TABLE_COLUMN_CHINESE.get("is_custom_attribute")%></dfhc:title>
				</dfhc:th>
				
				<dfhc:th width="100">
				   <dfhc:title templateId="title_h_ui" ><%=IRmPartyTypeConstants.TABLE_COLUMN_CHINESE.get("is_allow_hanging_user")%> </dfhc:title>
				</dfhc:th>
				
				<dfhc:th width="100">
				   <dfhc:title templateId="title_h_ui" ><%=IRmPartyTypeConstants.TABLE_COLUMN_CHINESE.get("is_allow_hanging_role")%></dfhc:title>
				</dfhc:th>
				
			</dfhc:tr>
    	   </dfhc:thead>			
		</dfhc:table>           
     </dfhc:region>        
     <dfhc:region name="footer"> 
     </dfhc:region> 
</dfhc:template>
<script type="text/javascript">
var _table;
$(function(){
	_table = $('.table-sort').DataTable({	
	     dom: 'Zlfrtip',	   		
		 ajax : function(data, callback, settings) {
		       var param =  splitParameter(data); 
                $.ajax({  
                        type: "POST",  
                        url: getRootPath()+'<%=CryptoHelper.encryptUrl(request,"/RmPartyTypeByHUI/ajaxList")%>',  
                        cache : false,  //禁用缓存  
                        data:param,   
                        dataType: "json",  
                        success: function(result) {  
                                //异常判断与处理  
                                if (result.status=='0') {  
                                    alert(result.message);  
                                    return;  
                                }  
                                //封装返回数据  
                                var returnData = {};  
                                returnData.draw = data.draw;//这里直接自行返回了draw计数器,应该由后台返回  
                                returnData.recordsTotal = result.recordsTotal;//总记录数  
                                returnData.recordsFiltered = result.recordsTotal;//后台不实现过滤功能，每次查询均视作全部结果  
                                returnData.data = result.data;  
                                //调用DataTables提供的callback方法，代表数据已封装完成并传回DataTables进行渲染  
                                //此时的数据需确保正确无误，异常判断应在执行此回调前自行处理完毕  
                                callback(returnData);  
                                //更新总记录数
                                $("#totalRecodSpan").html('共有数据：<strong>'+result.recordsTotal+'</strong> 条</span>');
                        },  
                        error: function(XMLHttpRequest, textStatus, errorThrown) {  
                            alert("查询失败");  
                        }  
                    });  
            },  
		"columns": [
		  {
		    "data":"id",
		    "width":"50px",
			"render":function(data,type,row,meta){
			   var content='<input type="checkbox" name="allId" value="'+row.id+'"/>';
			   return content; 
			}
		  },
		  {"data":"bs_keyword"},
		  {"data":"name"},
		 /*  {"data":"icon"}, */
		  {"data":"description"},
		  {"data":"is_custom_attribute",
			  "defaultContent":"",
			    render:function(data,type,row,meta){
			    	var content;
				   	if(row.is_custom_attribute!=null && row.is_custom_attribute!= ""){
					    if(row.is_custom_attribute=='1'){
					    	content = '是';
					    }else{
					    	content = '否';
					    }			 
				  }
			    return content; 
			  }
		  },
		  {"data":"is_allow_hanging_user",
			  "defaultContent":"",
			    render:function(data,type,row,meta){
			    	var content;
				   	if(row.is_allow_hanging_user !=null && row.is_allow_hanging_user != "" ){
					    if(row.is_allow_hanging_user=='1'){
					    	content = '是';
					    }else{
					    	content = '否';
					    }			 
				  }
			    return content; 
			  }
		  },
		  {"data":"is_allow_hanging_role",
			  "defaultContent":"",
			    render:function(data,type,row,meta){
			    	var content;
				   	if(row.is_allow_hanging_role !=null && row.is_allow_hanging_role != ""){
				   		
					    if(row.is_allow_hanging_role=='1'){
					    	content = '是';
					    }else{
					    	content = '否';
					    }			 
				  }
			    return content; 
			  }
		  }
		 
		],
		"columnDefs": [ {"searchable": false,
            "orderable": false,
            "targets": 0 }]  				
	});
	_table.on( 'draw.dt', function () {
	    var PageInfo = $('.table-sort').DataTable().page.info();
	         _table.column(0, { page: 'current' }).nodes().each( function (cell, i) {
	            cell.innerHTML = cell.innerHTML+"&nbsp;&nbsp;&nbsp;"+(i + 1);
	        } );
	    } );
});
/*拼接参数*/
function splitParameter(data){
	 var paramJsonStr = $(searchForm).serializeObject();
	 //组装 排序参数
	 if(data.order && data.order.length && data.order[0]){
	  data.sort = data.columns[data.order[0].column].data;
      if(data.sort!='0'){
      	data.dir = data.order[0].dir;
      }else{
        data.sort ='';
        data.dir='';
      }
	}  
	var retVal;
	retVal = $.extend( {}, data,paramJsonStr); 
	return retVal;
}


$.fn.serializeObject=function(){
    var o = {};
    var a = this.serializeArray();
    $.each(a, function() {
        if (o[this.name] !== undefined) {
            if (!o[this.name].push) {
                o[this.name] = [o[this.name]];
            }
            o[this.name].push(this.value || '');
        } else {
            o[this.name] = this.value || '';
        }
    });
    return o;
};
/**
 * 查询定制项目模块
 */
function _searchData(){	
	$('.table-sort').DataTable().ajax.reload();
} 
//详情
function detail(title,url,w,h){
	//判断用户是否选择
	var len = $('input[name="allId"]:checked').length;
    var count=0;
    var ids='';
     $('input[name="allId"]:checked').each(function(){
     	
     	var dataId =$(this).val();
     	if(dataId !== undefined && dataId!='on'){
     		ids+=dataId
         	if(len!=1){
         		ids+=","
         	}
         	count++;
     	}
     });  
    if(count==0){
       alert("请选择记录!");
       return;
    }  
    
    if(count>1){
       alert("只能选择一条记录!");
       return;	
    }
    var newUrl ;
    if(url.indexOf("?")>=0){
    	newUrl = url+'&id='+ids+'&jsguid='+ids;
    }else{
    	newUrl = url+'?id='+ids+'&jsguid='+ids;
    }
	var neww;
    var newh;
    
    if(w.indexOf("%")!=-1){
      neww = w; 
    }else{
      neww = w+'px';
    }
    if(h.indexOf("%")!=-1){
      newh = h; 
    }else{
      newh = h+'px';
    }
	layer.open({
			type: 2,
			area: [neww, newh],
			fix: true,
			shade:0.4,
			title: title,
			content: getRootPath()+newUrl,
            maxmin:true,
			cancel:function(){
				window.location.reload();
			}
	});
}
//单条删除
function singleDelete(url){
	//判断是否选择
	var len = $('input[name="allId"]:checked').length;
    var count=0;
    var ids='';
     $('input[name="allId"]:checked').each(function(){     	
     	var dataId =$(this).val();
     	if(dataId !== undefined && dataId!='on'){
     		ids+=dataId
         	if(len!=1){
         		ids+=","
         	}
         	count++;
     	}
     });  
    if(count==0){
       alert("请选择删除的记录!");
       return;
    }  
    
    if(count>1){
       alert("只能选择一条记录!");
       return;	
    }
    var newUrl ;
    if(url.indexOf("?")>=0){
    	newUrl = url+'&id='+ids+'&jsguid='+ids;
    }else{
    	newUrl = url+'?id='+ids+'&jsguid='+ids;
    }
    //url 后面自动带csrf 编码
	if(!isStrEmpty($('#_csrfcode_').val())){
		if (newUrl.indexOf("?") == -1) {
			newUrl = newUrl + "?_csrfcode_=" + $('#_csrfcode_').val();
		} else {
			newUrl = newUrl + "&_csrfcode_=" + $('#_csrfcode_').val();
		}
	}
	layer.confirm('确认要删除吗？',function(index){
		$.ajax({
			type: 'POST',
			url:getRootPath()+ newUrl,
			dataType: 'json',
			success: function(data){
				debugger;
				//$(obj).parents("tr").remove();
				layer.msg('已删除!',{icon:1,time:1000});
				window.location.reload();
			},
			error:function(data) {
				console.log(data.msg);
			},
		});		
	});
}
function singleEdit(title,url,w,h){
	//判断用户是否选择
	var len = $('input[name="allId"]:checked').length;
    var count=0;
    var ids='';
     $('input[name="allId"]:checked').each(function(){
     	
     	var dataId =$(this).val();
     	if(dataId !== undefined && dataId!='on'){
     		ids+=dataId
         	if(len!=1){
         		ids+=","
         	}
         	count++;
     	}
     });  
    if(count==0){
       alert("请选择记录!");
       return;
    }  
    
    if(count>1){
       alert("只能选择一条记录!");
       return;	
    }
    var newUrl ;
    if(url.indexOf("?")>=0){
    	newUrl = url+'&id='+ids+'&jsguid='+ids;
    }else{
    	newUrl = url+'?id='+ids+'&jsguid='+ids;
    }
	var neww;
    var newh;
    
    if(w.indexOf("%")!=-1){
      neww = w; 
    }else{
      neww = w+'px';
    }
    if(h.indexOf("%")!=-1){
      newh = h; 
    }else{
      newh = h+'px';
    }
	layer.open({
			type: 2,
			area: [neww, newh],
			fix: true,
			shade:0.4,
			title: title,
			content:getRootPath()+ newUrl,
            maxmin:true,
			cancel:function(){
				window.location.reload();
			},
			skin:'layui-layer-lan'
	});
}
</script> 
</body>
</html>